package zdx.lesson;

import java.util.Random;
import java.util.Scanner;


public class HomeWork
{
    //根据输入的年龄, 来打印出当前年龄的人是少年(低于18), 青年(19-28),
    // 中年(29-55), 老年(56以上)
    public static void main1(String[] args) {
        Scanner input = new Scanner(System.in);
        while (input.hasNextInt()) {
            int sc = input.nextInt();
            String string;
            if (sc <= 0) {
                System.out.println("年龄别输负数，怪瘆人的~");
                continue;
            }
            if (sc > 0 && sc <= 28) {
                string = sc <= 18 ? "少年" : "青年";
            } else {
                string = sc <= 55 ? "中年" : "老年";
            }
            System.out.println(string);
        }
    }

    //完成猜数字游戏 ，用户输入数字，判断该数字是大于，小于，还是等于随机生成的数字，
    // 等于的时候退出程序。
    public static void main2(String[] args) {
        Scanner input = new Scanner(System.in);
        Random random = new Random(20211124);
        int newNum = random.nextInt(100);
        System.out.println("生成的伪随机数是:" + newNum);
        while (true) {
            if (input.hasNextInt()) {
                int sc = input.nextInt();
                if (sc == newNum) {
                    System.out.println("结束！");
                    break;
                } else {
                    String ret = sc > newNum ? "大了" : "小了";
                    System.out.println(ret);
                }
            }
        }
    }

    static int cnt = 0;

    //三位数叫水仙花数，每位数字的三次方叫做水仙花数
    //那么四位数，五位数呢？
    public static void main4(String[] args) {

        Scanner scanner = new Scanner(System.in);
        while (true) {
            if (scanner.hasNextInt()) {
                int input = scanner.nextInt();
                if (input < 0) {
                    System.out.println("程序结束！");
                    break;
                }
                String[] StringArray = {"0", "1", "2", "水仙花数", "四叶玫瑰数", "五角星数", "六合数", "北斗七星数", "八仙过海数", "九九归一数"};
                System.out.println("您期望输出 " + input + " 位数的 " + StringArray[input] + "，结果如下：");
                narcissisticNum(input);
                System.out.println("共有：" + cnt + "位");
            }
        }

    }


    public static void narcissisticNum(int len) {

        cnt = 0;
        if (len <= 0) System.out.println("该长度的数字不存在水仙花");
        else if (len == 1) System.out.println("0 和 1 均是一位数的水仙花数");
        else {

//            for (int i = ((int) Math.pow(10, len - 1)); i < (int) (Math.pow(10, len )); i++)

            for (int i = pow_num_n(10, len - 1); i < pow_num_n(10, len); i++) {
                int last = 0;
                int sum = 0;
                int num = i;
                while (num != 0) {
                    last = num % 10;
                    sum += pow_num_n(last, len);
                    num /= 10;
                    if (num == 0 && i == sum) {
                        System.out.print(i + " ");
                        cnt++;
                    }

                }
            }
        }
    }

    public static int pow_num_n(int num, int n) {
        int pownum = 1;
        for (int i = 0; i < n; i++) {
            pownum *= num;
        }
        return pownum;
    }


    public static int getCntOfOne(int num){
        int one_cnt = 0;
        String string = Integer.toBinaryString(num);
        for(int i=0;i<string.length();i++){
            if(string.charAt(i)=='1'){
                one_cnt++;
            }
        }
        return one_cnt;
    }

    public static void main5(String[] args) {
        Scanner input = new Scanner( System.in);
        if(input.hasNextInt()){
            int sc = input.nextInt();
            System.out.println("您输入的十进制数字转换成二进制字符串是："+Integer.toBinaryString(sc)
                    +"B   其中包含一的个数是："+getCntOfOne(sc));
        }

    }

    public static void main(String[] args)
    {
        int[] arr = new int[]{1,4,3,3,2,2,3};
        System.out.println(isAsc(arr));
        int[] arr1 = new int[]{1,2,3,4,5,6};
        System.out.println(isAsc(arr1));
    }

    public static boolean isAsc(int[] nums){
        int len = nums.length;
        if(len==0 || len==1) return true;

        for(int i=0;i<len-1;i++){
            if(nums[i]>=nums[i+1]){
                return false;
            }
        }
        return true;


    }




}

